<div id="threads-pane">

  <% if permitted_to? :new, :forum_threads %>
    <div id="new-thread-button">
      <%= link_to 'New Thread', new_forum_thread_path(:forum_id => forum.id) %>
    </div>
  <% end %>

  <table class="forum-table">

    <tr id="forum-table-header">
      <th>Title</th>
      <th>Replies</th>
      <th>Views</th>
      <th>Last Post</th>
      <th></th>
    </tr>
   
    <% if forum.threads.empty? %>
      <tr class="thread">
        <td>
        No posts on this board. Make one? 
        </td>
        <td></td><td></td><td></td><td></td>
      </tr>
    <% else %>

    <% forum.threads.newest_first.each do |thread| %>
        <tr class="thread">
          <td class="thread-title">
            <span style="font-weight: bold; font-size: 15px;"><%= link_to thread.title, thread %></span><br />
            by: <%= link_to thread.user.username, user_path(thread.user) %> @
            <%=h thread.created_at.strftime('%d-%m-%y %I:%M %p') %>
          </td>
          <td class="thread-count"><%= thread.posts.size %></td>
          <td class="thread-views"><%= thread.views %></td>
          <td class="thread-last-post">
            by: <%= link_to thread.posts.last.user.username, user_path(thread.posts.last.user) %><br />
            <%=h thread.posts.last.created_at.strftime('%d-%m-%y %I:%M %p') %>
          </td>
          <td>
          <% if permitted_to? :edit, thread %>
            <%= link_to 'Edit', edit_forum_thread_path(thread) %>
          <% end %>

          <% if permitted_to? :destroy, thread %>
            <%= link_to 'Destroy', thread, :method => :delete, :confirm => "Are you sure?" %>
          <% end %>
          </td>
        </tr>
    <% end %>
    <% end %>
  </table>
</div>
